package com.yidu.ladder.base.controller;

import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.base.domain.Staff;
import com.yidu.ladder.base.domain.StaffVo;
import com.yidu.ladder.base.domain.Standard;
import com.yidu.ladder.base.domain.Time;
import com.yidu.ladder.base.service.StaffService;
import com.yidu.ladder.util.ID;
/**
 * 职员控制器
 * @author zzp
 *
 */
@Controller
@RequestMapping("/base/")
public class StaffController {
	@Autowired
	private StaffService staffService;

	public StaffService getStaffService() {
		return staffService;
	}

	public void setStaffService(StaffService staffService) {
		this.staffService = staffService;
	}

	public StaffController(StaffService staffService) {
		super();
		this.staffService = staffService;
	}
	public StaffController() {
		super();
	}
	

	@ResponseBody
	@RequestMapping(value = "Sdsdd")
	public List<Standard> selectAllSdsdd() {
		return staffService.selectAllSdsdd();
	}
	@ResponseBody
	@RequestMapping(value = "Testte")
	public List<Time> selectAllTes() {
		return staffService.selectAllTestte();
	}
	/**
	 * 检索
	 * 
	 * @param userVo 包装类
	 * @return 信息数据
	 */
	@ResponseBody
	@RequestMapping(value = "staffs")
	public Map<String, Object> queryUser(StaffVo staffVo) {
		//调用查询的方法
		Map<String, Object> userMap = staffService.pageQueryStaff(staffVo);
		return userMap;
	}
	/**
	 * 添加数据
	 * 
	 * @param archives
	 * @re9turn
	 */
	@RequestMapping(value = "addstaff", method = RequestMethod.POST)
	@ResponseBody
	public int addStaffs(Staff staff) {
		//随机生成一个Id
		staff.setStaffId(ID.getUUID());
		int dd = staffService.addstaff(staff);
		return dd;
	}
	/***
	 * 修改数据
	 * 
	 * @param archives
	 * @return
	 */
	@RequestMapping(value = "updatestaff", method = RequestMethod.POST)
	@ResponseBody
	public int updateStaff(Staff staff ) {
		  int dd = staffService.updatepicture(staff);
			return dd;
	}
	/*
	 * *** 删除
	 * 
	 * @param Staff
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="staff/{staffId}/{useable}",method=RequestMethod.DELETE)
	public String frozenORrecoverArchives(@PathVariable("staffId") String staffIdstr, @PathVariable("useable") String useable) {
		boolean result = staffService.updatefreeze(staffIdstr, useable);
		//判断result是false还是true
		if(result==false) {
			//给前端返回fail
			return "fail";
		}
		//给前端返回success
		return "success";
	}
}
